package cn.huihuo.weibo.controller;

import cn.huihuo.weibo.bean.user.UserBean;
import cn.huihuo.weibo.service.ParticipationService;
import cn.jfinalbbs.common.BaseController;
import cn.jfinalbbs.common.Constants;
import cn.jfinalbbs.user.User;

/**
 * Created by zhengjunbo on 2015/9/24.
 */
public class UserController extends BaseController {
    public void getSessionUser(){
        User user = getSessionAttr(Constants.USER_SESSION);
        UserBean userBean = new UserBean();
        userBean.setUserId("");
        userBean.setUserName("");

        if(user!=null){
            userBean.setUserId(user.getStr("id"));
            userBean.setUserAvatar(user.getStr("avatar"));
            userBean.setUserUrl(user.getStr("id"));
            userBean.setUserName(user.getStr("nickname"));
        }
        renderJson(userBean);
    }

    //获取整个用户信息
    public void index(){
        String userId = getPara();
        User user = User.me.findById(userId);
        if(user ==null){
            redirect("/");
            return;
        }

        User user1 = getSessionAttr(Constants.USER_SESSION);
        setAttr("participationSize", user1==null?"": ParticipationService.service.findTotalParticipation(user1.getStr("id")));
        setAttr("user",user);
        render("huihuo/userPage.html");
    }
}
